home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
examples
/
demo
/
demosrc
/
gettips.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
2KB
|
70 lines
;----------------------------------------------------------
;
; PURPOSE Read a file with a specified format (see below) and
; returns the text structure.
;
; File format :
;
; N
; id1 | text1
; id2 | text2
; .. ..
; idN | textN
;
; Where N is the number of lines( integer), idX and textX are
; string, | is the seperator string. The seperator can
; be customized by specifying the SEPERATOR keyword.
;
function gettips, $
filename , $ ; IN: string containing the file name
SEPERATOR = seperator ; IN: (opt) single character used as seperator.
; Returns if the filename is not present.
;
if (N_PARAMS() NE 1) then begin
PRINT, 'You must specify a file name'
PRINT, 'USAGE : textStructure = str2 (filename, SEPERATOR=characterString)'
RETURN, -1
endif
; If the seperator is not specified, make the '|' as default.
;
if (N_ELEMENTS(seperator) EQ 0) then begin
seperator = '|'
endif
; Open the file.
;
OPENR, lun, filename, /GET_LUN
; Read the first item. It is the number of text lines in the file.
;
READF, lun, nLines
; Initialize the working arrays.
;
str = ' '
parts = STRARR(nLines,2)
; Read one line at a time. Seperate the line in two parts :
;
; 1) The string id
; 2) The text body
;
for i = 0, nLines-1 do begin
READF, lun, str
parts[i,*] = STR_SEP(str, seperator)
endfor
; Form the text structure.
;
sText= { id : parts[*,0], text : parts[*,1] }
CLOSE, lun
FREE_LUN, lun
RETURN, sText
end